package huawei.js2025;

import java.util.Scanner;

/**
 * 需要打开多少监控器
 */
public class Question37 {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int m = in.nextInt();
        int n = in.nextInt();

        boolean[][] needLight = new boolean[m][n]; // 是否需要灯光

        int[][] direction = {{0, 0},{0, 1},{1, 0},{0, -1},{-1, 0}};

        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n; j++) {
                if (in.nextInt() == 1) {
                    for (int k = 0; k < direction.length; k++) {
                        int x = i + direction[k][0];
                        int y = j + direction[k][1];

                        if (x >= 0 && x < m && y >= 0 && y < n) {
                            needLight[x][y] = true;
                        }
                    }
                }
            }
        }

        int needLightCount = 0;
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n; j++) {
                if (needLight[i][j]) {needLightCount += 1;}
            }
        }

        System.out.println(needLightCount);
    }
}
